import { logger } from '../types/constants'

export class LoggerDeduplicator {
  private static instance: LoggerDeduplicator
  private infoMessages = new Set<string>()
  private warnedMessages = new Set<string>()
  private errorMessages = new Set<string>()
  private highlightedMessages = new Set<string>()

  private constructor() {}

  public static getInstance(): LoggerDeduplicator {
    if (!LoggerDeduplicator.instance) {
      LoggerDeduplicator.instance = new LoggerDeduplicator()
    }
    return LoggerDeduplicator.instance
  }

  public info(message: string, data?: any): void {
    if (!this.infoMessages.has(message)) {
      logger.info(message, data)
      this.infoMessages.add(message)
    }
  }

  public warn(message: string, data?: any): void {
    if (!this.warnedMessages.has(message)) {
      logger.warn(message, data)
      this.warnedMessages.add(message)
    }
  }

  public error(message: string, data?: any): void {
    if (!this.errorMessages.has(message)) {
      logger.error(message, data)
      this.errorMessages.add(message)
    }
  }

  public highlight(message: string, data?: any): void {
    if (!this.highlightedMessages.has(message)) {
      logger.attention(message, data)
      this.highlightedMessages.add(message)
    }
  }

  public clear(): void {
    this.infoMessages.clear()
    this.warnedMessages.clear()
    this.errorMessages.clear()
    this.highlightedMessages.clear()
  }
}
